package com.db.gffxo.epi.controller;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ControllerBootstrap {

	private Controller controller;
	/**
	 * @param args
	 */
	
	public void boot (String ConfigFile) {
		//"FormatController-SpringConfig.xml"
		ApplicationContext ac = new ClassPathXmlApplicationContext(ConfigFile);
		controller = (Controller) ac.getBean("controller");
		controller.setApplicationContext(ac);
		Thread t = new Thread(controller);
		t.start();
		
		while (true) {
			// Add check for shutdown
			try {
				Thread.sleep(10000);
				//t.interrupt();
			} catch (InterruptedException e) {
			}
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub {
		
		int i = 0;
		String ConfigFile = "DefaultController-SpringConfig.xml";
		while(i<args.length){
			if (args[i].equals("-c")) {
				i++;
				ConfigFile=args[i];
			} else {
				usage();
			}
			i++;
		}
		
		ControllerBootstrap s = new ControllerBootstrap();
		s.boot(ConfigFile);

	}
	
	public static void usage() {
		System.out.println("Valid Parameters: -c ConfigFile");
		System.exit(0);
	}

}
